package com.rika.controller;

import com.rika.pojo.SoMain;
import com.rika.pojo.StockRecord;
import com.rika.response.QueryResult;
import com.rika.response.Result;
import com.rika.service.StockRecordService;
import com.rika.util.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class StockRecordController {
    @Resource
    private StockRecordService stockRecordService;

    @RequestMapping("getAllInStockRecord")
    public QueryResult selectAllInStockRecord(Integer currentPage, Integer pageSize,String productCode){
        Page page=new Page(currentPage,pageSize);
        Map<String,Object> params=new HashMap<>();
        params.put("first",page.getFirst());
        params.put("max",page.getMax());
        params.put("productCode",productCode);
        List<StockRecord> list=stockRecordService.selectInStockRecord(params);
        int total=stockRecordService.countAllIn(productCode);
        return QueryResult.ok(total,list);
    }
    @RequestMapping("getAllOutStockRecord")
    public QueryResult selectAllOutStockRecord(Integer currentPage, Integer pageSize,String productCode){
        Page page=new Page(currentPage,pageSize);
        Map<String,Object> params=new HashMap<>();
        params.put("first",page.getFirst());
        params.put("max",page.getMax());
        params.put("productCode",productCode);
        List<StockRecord> list=stockRecordService.selectOutStockRecord(params);
        int total=stockRecordService.countAllOut(productCode);
        return QueryResult.ok(total,list);
    }
    @RequestMapping("selectInStore")
    public Result selectInStore(String date){
        Result result=new Result();
        String[] Date=date.split("~");
        Map<String,Object> params=new HashMap<>();
        params.put("startTime",Date[0].trim());
        params.put("endTime",Date[1].trim());
        List<StockRecord> inStore=stockRecordService.selectInStore(params);
        result.setCode(200);
        result.setData(inStore);
        return result;
    }
    @RequestMapping("selectInStorePrice")
    public Result selectInStorePrice(String date){
        Result result=new Result();
        String[] Date=date.split("~");
        Map<String,Object> params=new HashMap<>();
        params.put("startTime",Date[0].trim());
        params.put("endTime",Date[1].trim());
        List<StockRecord> inStore=stockRecordService.selectInStorePrice(params);
        result.setCode(200);
        result.setData(inStore);
        return result;
    }
    @RequestMapping("selectOutStore")
    public Result selectOutStore(String date){
        Result result=new Result();
        String[] Date=date.split("~");
        Map<String,Object> params=new HashMap<>();
        params.put("startTime",Date[0].trim());
        params.put("endTime",Date[1].trim());
        List<StockRecord> outStore=stockRecordService.selectOutStore(params);
        result.setCode(200);
        result.setData(outStore);
        return result;
    }
    @RequestMapping("selectOutStorePrice")
    public Result selectOutStorePrice(String date){
        Result result=new Result();
        String[] Date=date.split("~");
        Map<String,Object> params=new HashMap<>();
        params.put("startTime",Date[0].trim());
        params.put("endTime",Date[1].trim());
        List<StockRecord> outStore=stockRecordService.selectOutStorePrice(params);
        result.setCode(200);
        result.setData(outStore);
        return result;
    }
}
